package app.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import sun.security.util.Password;
import app.dao.ApplicationDao;
import app.dao.MemberDao;
import app.model.Application;
import app.model.Member;
import app.model.Role;

/** 
 * 
 * @author Nachman Mathieu
 * @author David Gianorio
 * @author Faton Alia
 * 
 * This class will manage all the members business logic methods */

@Component
public class MemberService {

	@Autowired MemberDao memberDao;
	@Autowired ApplicationDao applicationDao;
	
	/** This method will get all members stored in the DB */
	public List<Member> getAllMembers(){
		return memberDao.getAllMembers();
	}
	
	/** Method used only for local tests - Creating starting data 
	 * 	TODO : remove this method later
	 * */
	public void createMembersData(){
		
		Member memb1 = new Member("1","1",Role.SIMPLE_USER,"user","pass");
		Member memb2 = new Member("2","2",Role.SIMPLE_USER,"user","pass");
		Member memb3 = new Member("3","3",Role.SIMPLE_USER,"user","pass");
		Member memb4 = new Member("4","4",Role.SIMPLE_USER,"user","pass");
		Member memb5 = new Member("5","5",Role.SIMPLE_USER,"user","pass");
	
		memberDao.persist(memb1);
		memberDao.persist(memb2);
		memberDao.persist(memb3);
		memberDao.persist(memb4);
		memberDao.persist(memb5);
		
		Application app1 = new Application("app1","app1",new Date(),"app1",0,0,memb1);
		Application app2 = new Application("app2","app2",new Date(),"app2",0,0,memb1);
		Application app3 = new Application("app3","app3",new Date(),"app3",0,0,memb1);
		Application app4 = new Application("app4","app4",new Date(),"app4",0,0,memb1);
		Application app5 = new Application("app5","app5",new Date(),"app5",0,0,memb1);
		
		applicationDao.persist(app1);
		applicationDao.persist(app2);
		applicationDao.persist(app3);
		applicationDao.persist(app4);
		applicationDao.persist(app5);
	}
}
